#include  <stdio.h>
#include<string.h>
#define SIZE 100
void GetKey(char code[],char key[][5]);
int GetPair(char text[], char text_pair[][2]);
void GetCipher(char key[][5], char text_pair[]);
int main()
{
	char code[SIZE],text[SIZE];
	char key[5][5] = { '\0' };
	char text_pair[SIZE][2] = { '\0' };
	int pair,i;
	scanf("%s", &code);
	scanf("%s", &text);
	GetKey(code, key);
	pair=GetPair(text, text_pair);
	for(i=0;i<=pair;i++)
		GetCipher(key, text_pair[i]);


	return 0;
}
void GetKey(char code[], char key[][5])
{
	char pre_key[SIZE] = { '\0' };
	int i = 0, j = 0, k = 0, flag = 1;
	while (code[i] != '\0')
	{
		if (code[i] == 'j')
			code[i] = 'i';
		if (code[i] ==' '|| code[i] == '\n')
			flag = 0;
		for (j = 0; j < i - 1; j++)
			if (code[i] == code[j])
			{
				flag = 0;
				break;
			}
		if (flag)
			pre_key[k] = code[i];
		i++;
		k++;
	}
	for (i = 0; i < k; i++)
		key[i / 5][i % 5] = pre_key[i];
	i = k;
	for (j = 97; j < 123; j++)
	{
		flag = 1;
		if (j == 106)
			flag = 0;
		for (int m = 0; m < k; m++)
			if (j == int(pre_key[m]))
			{
				flag = 0;
				break;
			}
		if (flag)
		{
			key[i / 5][i % 5] = j;
			i++;
		}		
	}
	/*for (i = 0; i < 5; i++)
		for (j = 0; j < 5;j++)
			printf("%c", key[i][j]);*/
	return;
}
int GetPair(char text[], char text_pair[][2])
{
	int i,j,lenth;
	lenth = strlen(text);
	text_pair[0][0] = text[0];
	for (i = 1, j = 1; i < lenth; i++)
	{
		if (text[i] == text[i - 1]&&text_pair[(j-1)/2][(j-1) % 2]!='x')
		{
			text_pair[j / 2][j % 2] = 'x';
			i--;			
		}
		else		
			text_pair[j / 2][j % 2] = text[i];
		j++;
	}
	if (j % 2 == 1)
		text_pair[j / 2][j % 2] = 'x';
	return j / 2;
	/*int k, m;*/
	/*for (k = 0; k <= j / 2; k++)
	{
		for (m = 0; m < 2; m++)
		{
			printf("%c", text_pair[k][m]);
		}
		printf("\n");
	}*/
	
}
void GetCipher(char key[][5], char text_pair[])
{
	int i,j,k,row[2], colum[2];
	for(k=0;k<2;k++)
		for(i=0;i<=5;i++)
			for(j=0;j<5;j++)
				if (text_pair[k] == key[i][j])
				{
					row[k] = i;
					colum[k] = j;
				}
	if (row[0] == row[1])
		printf("%c%c", key[row[0]][(colum[0] + 1) % 5], key[row[1]][(colum[1] + 1) % 5]);
	else if (colum[0] == colum[1])
		printf("%c%c", key[(row[0] + 1) % 5][colum[0]], key[(row[1]+ 1) % 5][colum[1] ]);
	else
		printf("%c%c", key[row[0]][colum[1]], key[row[1]][colum[0]]);
}